﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Revis.VClinicNet.Core.Domain
{
    public class Worker : IEquatable<Worker>
    {
        public virtual long Id { get; protected set; }
        public virtual string FirstName { get; protected set; }
        public virtual string Surname { get; protected set; }
        public virtual bool IsActive { get; protected set; }

        #region Constructors

        public Worker()
            : this(0, String.Empty, String.Empty)
        {
        }

        public Worker(string firstName, string surname) :
            this(0, firstName, surname)
        {
        }

        public Worker(long id, string firstName, string surname)
        {
            SetUpFields(firstName, surname);
            Id = id;
            IsActive = true;
        }

        #endregion

        #region Public Methods

        public virtual void Change(string firstName, string surname)
        {
            SetUpFields(firstName, surname);
        }

        public virtual void SetInactive()
        {
            SetActivity(false);
        }

        public virtual void SetActive()
        {
            SetActivity(true);
        }

        public virtual void SetActivity(bool isActive)
        {
            IsActive = isActive;
        }


        public override bool Equals(object obj)
        {
            return Equals(obj as Worker);
        }

        public virtual bool Equals(Worker other)
        {
            if (other == null) {
                return false;
            }
            return other.Id == this.Id;
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode() ^ base.GetHashCode();
        }

        #endregion

        #region Private Methods

        private void SetUpFields(string firstName, string surname)
        {
            if (firstName == null) {
                throw new ArgumentNullException("Null firstName");
            }
            if (surname == null) {
                throw new ArgumentNullException("Null surname");
            }
            FirstName = firstName;
            Surname = surname;
        }

        #endregion

    }
}
